﻿using Common.Commands;
using Common.Commands.MemberCommands;
using Core.Domain.Model;
using Core.Infrastructure.CustomExceptions;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.MemberProcessors
{
    public class UpdateMemberNotificationProcessor : ICommandProcessor<UpdateMemberNotification>
    {
        private readonly IRepository<Member> _memberRepository;

        public UpdateMemberNotificationProcessor(IRepository<Member> memberRepository)
        {
            _memberRepository = memberRepository;
        }

        public dynamic Process(UpdateMemberNotification command)
        {
            var response = new WebApiResultResponse();
            var entity = _memberRepository.GetById(command.Id);
            if (entity == null) throw new DomainProcessException("Invalid command supplied for Site User");
            entity.Email = command.Email;
            entity.SendEmail = command.SendEmail;
            entity.SendSms = command.SendSms;
            entity.UsePrint = command.UsePrint;
            entity.Block = command.Block;
            _memberRepository.Update(entity);
            response.IsSuccess = true;
            return response;
        }

    }
}